<?php

tsLoad('/core/CoreLib/AbstractMysqlPage.class.php');
class RecomUserPage extends AbstractMysqlPage {
	/*
	 * 取得总的行数
	 */
	protected function calTotalRows (){
		global $mysqlTools,$userSession;
        $condition = $mysqlTools->check_input($this->condition,array('userLoginId'));
        $userId =$userSession->getUserSession()["userId"];
       	$sqlCore = "
       		select
				count(*) as totalCount
			from user_bop_info  uii left join sys_user u on uii.userInFUserId=u.userId
			left join sys_role role on uii.roleId=role.roleId	
        ";
        $where = "
         	WHERE 1=1  AND uii.userInFUserId=$userId
        ";
        if(!empty($condition['userInFZf']) && $condition['userInFZf']!=3){
        	$where.= ' AND uii.userInFZf ='.$condition['userInFZf'];
        }
		//查看类型
        if(!empty($condition['userInFType']) && $condition['userInFType']!=4){
        	$where.= ' AND uii.userInFType ='.$condition['userInFType'];
        }
        //查看事由
        if(!empty($condition['userInFReason']) && $condition['userInFReason']!=4){
        	$where.= ' AND uii.userInFReason ='.$condition['userInFReason'];
        }
        
        //创建开始时间与结束时间
        if(!empty($condition['withdCreatetimeStart'])){
        	$where.= ' AND uii.userInFCreatetime >='.$condition['withdCreatetimeStart'];
        }
        if(!empty($condition['withdCreatetimeEnd'])){
        	$where.= ' AND uii.userInFCreatetime <='.$condition['withdCreatetimeEnd'];
        }
        
        $sql = $sqlCore.$where;
        //总记录数
        $totalRows = $mysqlTools->selectSql($sql)[0]['totalCount'];
        
        return $totalRows;
	}
	
	/*
	*取得数据集合
			*/
	protected function getList ($sRowNo, $pageRows)
	{
	  global $mysqlTools,$userSession;
        
        //保存一个原生值以便需要的时候进行处理
        $orgCondition = $this->condition;
        
        $condition = $mysqlTools->check_input($this->condition,array('userLoginId'));
        $userId =$userSession->getUserSession()["userId"];
        $sqlCore = "
				    select
						uii.userInFId,
						uii.userInFZf,
						uii.userInFUserId,
						uii.userInFLoginId,
						uii.userInFCreatetime,
						uii.userInFType,
						uii.userInFMo,
						uii.roleId,
						uii.roleDesc,
						uii.userInFOthMo,
						uii.userInFReason,
						uii.userInFSurGlod
					from user_bop_info  uii left join sys_user u on uii.userInFUserId=u.userId
					left join sys_role role on uii.roleId=role.roleId
        ";
        
        $where = "
         	WHERE 1=1  AND uii.userInFUserId=$userId
        ";
        
        if(!empty($condition['userInFZf']) && $condition['userInFZf']!=3){
        	$where.= ' AND uii.userInFZf ='.$condition['userInFZf'];
        }
        if(!empty($condition['userInFType']) && $condition['userInFType']!=4){
        	$where.= ' AND uii.userInFType ='.$condition['userInFType'];
        }
        //查看事由
        if(!empty($condition['userInFReason']) && $condition['userInFReason']!=4){
        	$where.= ' AND uii.userInFReason ='.$condition['userInFReason'];
        }
        
        //创建开始时间与结束时间
        if(!empty($condition['withdCreatetimeStart'])){
        	$where.= ' AND uii.userInFCreatetime >='.$condition['withdCreatetimeStart'];
        }
        if(!empty($condition['withdCreatetimeEnd'])){
        	$where.= ' AND uii.userInFCreatetime <='.$condition['withdCreatetimeEnd'];
        }
        
        $order = "";
        if(!empty($orgCondition['order'])&&!empty($orgCondition['sort'])){
        	$order = " ORDER BY uii.".$orgCondition['sort']." ".$orgCondition['order']." ";
        }else{
        	$order = " ORDER BY uii.userInFCreatetime DESC ";
        }
        $limit = " LIMIT $sRowNo,$pageRows";
        
        $sql = $sqlCore.$where.$order.$limit;
        
        //查询角色信息分页
        $list = $mysqlTools->selectSql($sql);
        
        return $list;
	}
	//获取余额
	public function getAllUserInFMo($condition){
		global $mysqlTools,$userSession;
		$userId =$userSession->getUserSession()["userId"];
		$sqlCore = "
       		select sum(userInFMo) as totalMo  from user_bop_info uii
        ";
		$where = "
		WHERE 1=1  AND uii.userInFUserId='$userId'
		";
		if(!empty($condition['userInFZf']) && $condition['userInFZf']!=3){
			$where.= ' AND uii.userInFZf ='.$condition['userInFZf'];
		}
		//查看类型
		if(!empty($condition['userInFType']) && $condition['userInFType']!=4){
		$where.= " AND uii.userInFType =".$condition['userInFType'];
		}
				//查看事由
		if(!empty($condition['userInFReason']) && $condition['userInFReason']!=4){
		$where.= " AND uii.userInFReason =".$condition['userInFReason'];
        }
		
		//创建开始时间与结束时间
		if(!empty($condition['withdCreatetimeStart'])){
		$where.= " AND uii.userInFCreatetime >='".$condition['withdCreatetimeStart']."'";
		}
		
        if(!empty($condition['withdCreatetimeEnd'])){
		$where.= " AND uii.userInFCreatetime <='".$condition['withdCreatetimeEnd']."'";
		}
// 		return $where;
		$sql = $sqlCore.$where;
        //总记录数
		$totalMo = $mysqlTools->selectSql($sql)[0]['totalMo'];
		
		return $totalMo;
	}
}
?>